using System;
using System.Collections.Generic;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.IO;

using MakeIT.Look.Imagem.Entidades;
using MakeIT.Look.Imagem.Negocios;

namespace MakeIT.Look.Imagem.Apresentacao
{
	public partial class DownBooklkifotoFoto : System.Web.UI.Page
	{
 		protected LookDAOT daoT = null;
		protected void Page_Load(object sender, EventArgs e)
		{
			this.daoT = new LookDAOT();

			//Recupera dados
			BooklkifotoVO booklkifotoVO = BooklkifotoVO.CreateVO();
			booklkifotoVO.idBookLkiFoto = Int32.Parse(Request["idBookLkiFoto"]);
			this.daoT.getBooklkifotoFoto(booklkifotoVO);

			if (booklkifotoVO.foto != null)
			{
				Response.ContentType = booklkifotoVO.fotoMime;
				Response.AppendHeader("Content-Disposition", "attachment; filename=" + booklkifotoVO.fotoNome);

				Response.BinaryWrite(booklkifotoVO.foto);
				return;
			}

			Response.ContentType = "image/png";
			Response.AppendHeader("Content-Disposition", "attachment; filename=SemFoto.png");
			string filePath = HttpContext.Current.Server.MapPath("~/App_Themes/Padrao/Imagens/backoffice/SemFoto.png");
			Response.BinaryWrite(File.ReadAllBytes(filePath));
		}

		protected void Page_Unload(object sender, EventArgs e)
		{
			try
			{
				if (this.daoT != null)
					this.daoT.closeDAO();
			}
			catch (Exception ex){}
		}

	}
}
